package com.google.code.dajly.model;

import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;

/***Classe che rappresenta un tipo di Filtro
 * @author stefano pigozzi*/
public class FilterType {
	
	private Hashtable<String, Boolean> types = new Hashtable<String, Boolean>();
	private LinkedList<String> filters = new LinkedList<String>();
	
	public boolean isAuthor() {
		return this.types.get("author");
	}
	
	public boolean isDescription() {
		return this.types.get("description");
	}
	
	public boolean isTitle() {
		return this.types.get("title");
	}
	
	public boolean isBusiness() {
		return this.types.get("business");
	}
	
	public boolean isLocation() {
		return this.types.get("location");
	}
	
	public List<String> getFilter() {
		return filters;
	}
	
	/**Inizializza un FilterType nullo!*/
	public FilterType() {
		this.types.put("author", false);
		this.types.put("description", false);
		this.types.put("title", false);
		this.types.put("business",false);
		this.types.put("location", false);
	}
	
	/***Imposta il tipo di filtro
	 * @param type [String...] tipo di filtro, valori accettati: all, author, description, title, business, location
	 * @return this*/
	public FilterType setType (String... type){
		
		this.types.put("author", false);
		this.types.put("description", false);
		this.types.put("title", false);
		this.types.put("business",false);
		this.types.put("location", false);

		if (type != null){

			for (String _t : type)
				if(_t.equalsIgnoreCase("all")) {
					this.types.put("author", true);
					this.types.put("description", true);
					this.types.put("title", true);
					this.types.put("business",true);
					this.types.put("location", true);
				} else if(this.types.containsKey(_t.toLowerCase()))
					this.types.put(_t.toLowerCase(), true);

		}
		
		return this;
	}
	
	/***Imposta il filtro
	 * @param filter [String...] filtro
	 * @return this*/
	public FilterType setFilter(String... filter) {
		if(filter == null){
			for(int i = 0 ; i< this.filters.size() ; i++)
				this.filters.remove(i);
		} else {
		for (String  _f : filter)
			this.filters.add(_f);
		}
		return this;
	}

}
